import 'package:Smart/pages/productor007/studytest/flutter_boss/item/messagelist_item.dart';
import 'package:Smart/pages/productor007/studytest/flutter_boss/model/message.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_boss/item/messagelist_item.dart';
// import 'package:flutter_boss/model/message.dart';


class ChatAllTab extends StatefulWidget {
  ChatAllTab({Key key}) : super(key: key);

  @override
  _ChatAllTabState createState() => _ChatAllTabState();
}

class _ChatAllTabState extends State<ChatAllTab> {
  List<Message> _messages = [];
  @override
  void initState() {
    super.initState();
    getMessageList();
  }

  @override
  Widget build(BuildContext context) {
    // return Center(child:Text('hhhhhh'));
    return ListView.builder(
        itemCount:_messages.length, 
        itemBuilder: buildMessageItem
      );
  }

  Widget buildMessageItem(BuildContext context, int index) {
    Message message = _messages[index];
    var msgItem = new InkWell(
      onTap: () {
        showDialog(
            context: context,
            child: AlertDialog(
              content: Text(
                "尽情期待",
                style: TextStyle(fontSize: 20.0),
              ),
            ));
      },
      child: new MessageListItem(message)
    );
    return msgItem;
  }

   void getMessageList() {
    setState(() {
      // list数据中的最后一项不能有逗号 "msg":"[新招呼]该职位共**人投递"
      _messages = Message.fromJson("""
        {
          "list":[
            {
              "avatar":"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg",
              "name":"张女士",
              "company":"飞行石科技(大数据)",
              "position":"HR",
              "msg":"[新招呼]该职位共**人投递",
              "time":"12月25日"
            },
            {
              "avatar":"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg",
              "name":"李女士",
              "company":"飞行石科技(大数据)",
              "position":"HR",
              "msg":"[新招呼]该职位共**人投递",
              "time":"11月8日"
            }
          ]
        }
      """);
    });
  }
}